$(document).ready(function(){
//	var l = console.log;
	$(document).on('change', 'form input, form select', function(e){
		onChange(e.target);
	});

	function onChange(el)
	{
		var $el = $(el);
		var $form = $($el.parents('form'));
		var action = $form.attr('action') ? $form.attr('action') : window.location.pathname;
		var value = $el.val();
		var name = $el.attr('name');
		var data = {};
		data[name] = value;

		$.ajax({
			'type': 'POST',
			'url': action,
			'data': data
		}).done(function(data){
			var $wrapper = $('<div></div>');
			$wrapper.append(data);
			$wrapper.find('.element-block').each(function(){
				var id = $(this).find('[data-element="master"]').attr('id');
				$form.find('#' + id).parents('.element-block').html($(this).html());
			});
		});
	}

	function test()
	{
		onChange($('form input').get(0));
	}
//	test();
});